//
//  MXHomeContentCollectionViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/5.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXHomeContentCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@interface MXHomeContentCollectionViewCell ()
@property (nonatomic, retain) UIView *line;
@end
@implementation MXHomeContentCollectionViewCell

- (void)dealloc
{
    [_line release];
    [_baoyouImage release];
    [_mailFreeModelS release];
    [_modelS release];
    [_mainImage release];
    [_titleLabel release];
    [_priceLabel release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.mainImage = [[[UIImageView alloc] init] autorelease];
        self.mainImage.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.mainImage];
        
        self.titleLabel = [[[UILabel alloc] init] autorelease];
        self.titleLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.titleLabel];
        
        self.priceLabel = [[[UILabel alloc] init] autorelease];
        self.priceLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.priceLabel];
        
        self.line = [[[UIView alloc] init] autorelease];
        self.line.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview: self.line];
        
        self.baoyouImage = [[[UIImageView alloc] init] autorelease];
        self.baoyouImage.backgroundColor = [UIColor clearColor];
        [self.priceLabel addSubview:self.baoyouImage];
        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    // flowLayout.itemSize = CGSizeMake(170, 240);

    CGFloat WID = self.frame.size.width;
    
    
    self.mainImage.frame = CGRectMake(0, 0, WID, WID);
    
    self.titleLabel.frame = CGRectMake(0, WID, WID, WIDTH / 375 * 40);
    self.titleLabel.numberOfLines = 2;
    self.titleLabel.font = [UIFont systemFontOfSize:12];
    
    self.priceLabel.frame = CGRectMake(0, WID + self.titleLabel.frame.size.height, WID, HEIGHT / 667 * 30);
    [self.priceLabel setTextColor:[UIColor redColor]];
    
    self.line.frame = CGRectMake(WIDTH / 375 * 20, WID + HEIGHT / 667 * (40 - 1), self.titleLabel.frame.size.width - WIDTH / 375 * (2 * 20), 1);
    self.baoyouImage.frame = CGRectMake(WID - WIDTH / 375 * 50, HEIGHT / 667 * 2.5, WIDTH / 375 * 40, HEIGHT / 667 * 25);
    
    
    
}
-(void)getInfo:(MXHomeContentModel *)model
{
    if (_modelS != model) {
        [_modelS release];
        _modelS = [model retain];
    }
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:model.pic_url] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    self.titleLabel.text = model.title;
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", model.coupon_price];
}
- (void)getWashInfo:(MXHomeWashDetailModel *)washModel
{
    if (_washModelS != washModel) {
        [_washModelS release];
        _washModelS = [washModel retain];
    }
    
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:washModel.pic_url] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    self.titleLabel.text = washModel.title;
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", washModel.coupon_price];
}

-(void)getmailFreeInfo:(MXHomeMailFreeModel *)mailFreeModel
{
    if (_mailFreeModelS != mailFreeModel) {
        [_mailFreeModelS release];
        _mailFreeModelS = [mailFreeModel retain];
    }
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:mailFreeModel.pic_url] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    self.titleLabel.text = mailFreeModel.title;
    
    self.baoyouImage.image = [UIImage imageNamed:@"baoyou"];
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", mailFreeModel.coupon_price];
}
@end
